package com.anttribe.components.infra.lang.reflect.scanner;

import lombok.Getter;
import lombok.Setter;
import org.apache.commons.collections4.CollectionUtils;

import java.util.HashSet;
import java.util.Set;
import java.util.function.Predicate;

/**
 * @author zhaoyong
 * @date 2021/11/4 0004
 */
@Getter
@Setter
public class ClassScannerExecutor implements ClassScanner {

    /**
     * 类加载路径
     */
    private String classpath;

    @Override
    public Set<Class<?>> scan(String basePackage, Predicate<Class<?>> predicate) {
        Set<Class<?>> scanClasses = new HashSet<>();
        FileClassScanner fileClassScanner = new FileClassScanner();
        Set<Class<?>> fileScanClasses = fileClassScanner.scan(basePackage, predicate);
        if (!CollectionUtils.isEmpty(fileScanClasses)) {
            scanClasses.addAll(fileScanClasses);
        }

        JarClassScanner jarClassScanner = new JarClassScanner();
        Set<Class<?>> jarScanClasses = jarClassScanner.scan(basePackage, predicate);
        if (!CollectionUtils.isEmpty(jarScanClasses)) {
            scanClasses.addAll(jarScanClasses);
        }
        return scanClasses;
    }

}
